package com.slfx.idgen.server.mapper;

import com.slfx.idgen.server.dto.GuidHolder;
import com.slfx.idgen.server.entity.Guid;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import lombok.Data;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectKey;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author slfx
 * @since 2023-01-06
 */
public interface GuidMapper extends BaseMapper<Guid> {

    /**
     * 获取全局唯一ID
     *
     * @return
     */
    // replace into afs_guid(stub) values('a');
    // select last_insert_id();
    @Insert("REPLACE INTO guid (stub) VALUES(#{guidHolder.stub})")
    @SelectKey(statement = {"SELECT LAST_INSERT_ID()"}, keyProperty = "guidHolder.id", before = false, resultType = long.class)
    int getGuid(@Param("guidHolder") GuidHolder guidHolder);


    int getGuid2(@Param("guid") Guid guid);



    int getGuid3(@Param("guidHolder") GuidHolder guidHolder);
}
